/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import Model.Config;
import Model.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author pyty
 */
public class MediumTableModel extends AbstractTableModel {

    private List<Medium> mediums = new ArrayList<Medium>();
    private Locale locale = Config.LOCALE;
    private ResourceBundle texts = ResourceBundle.getBundle(Config.TEXTS_FILE, locale);
    
    @Override
    public int getRowCount() {
        return mediums.size();
    }
 
    @Override
    public int getColumnCount() {
        return 4;
    }
 
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Medium medium = mediums.get(rowIndex);
        switch (columnIndex) {
            /*case 0:
                return medium.getId();*/
            case 0:
                return medium.getName();
            case 1:
                return medium.getAuthor();
            case 2:
                return medium.getType();
            case 3:
                return medium.getDescription();
            default:
                throw new IllegalArgumentException("columnIndex");
        }
    }
    
    public void removeAll() {
        mediums.removeAll(mediums);
    }
    
    public Medium getValueAt(int rowIndex) {
        return mediums.get(rowIndex);
    }
    
    public void addMedium(Medium medium) {
        mediums.add(medium);
        int lastRow = mediums.size() - 1;
        fireTableRowsInserted(lastRow, lastRow);   
    }
    
    public void deleteValue(Medium medium) {
        mediums.remove(medium);
        fireTableDataChanged();
    }
 
    @Override
    public String getColumnName(int columnIndex) {
        switch (columnIndex) {
            /*case 0:
                return "Id";*/
            case 0:
                return texts.getString("name");
            case 1:
                return texts.getString("author");
            case 2:
                return texts.getString("type");
            case 3:
                return texts.getString("description");
            default:
                throw new IllegalArgumentException("columnIndex");
        }
    }
    
    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            /*case 0:
                return Integer.class;*/
            case 0:
            case 1:
            case 2:
            case 3:    
                return String.class;
            default:
                throw new IllegalArgumentException("columnIndex");
        }
    }
    
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
            case 1:
            case 2:
            case 3:
                return false;
            default:
                throw new IllegalArgumentException("columnIndex");
        }
    }    

    
    
}
